package com.enterprise.projectManager.service.implemention;

import com.enterprise.projectManager.rope.UserRope;
import com.enterprise.projectManager.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserImpl implements UserService {

    private final UserRope userRope;

    @Override
    public UserDetailsService userDetailsService() {
        return new UserDetailsService() {
            @Override
            public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
                return userRope.findByAccount(account)
                        .orElseThrow(() -> new UsernameNotFoundException("user not found"));
            }
        };
    }
}
